//
//  SMAddSaveMoneyViewController.m
//  SaveMoney
//
//  Created by user on 2018/11/23.
//  Copyright © 2018年 Sunflower. All rights reserved.
//

#import "SMAddSaveMoneyViewController.h"

#import "XWInteractiveTransition.h"
#import "XWPresentOneTransition.h"
#import "SMAddSaveOneTableViewCell.h"
#import "SMAddSaveTwoTableViewCell.h"

@interface SMAddSaveMoneyViewController ()<UIViewControllerTransitioningDelegate,UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) XWInteractiveTransition *interactiveDismiss;
@property (nonatomic, strong) XWInteractiveTransition *interactivePush;

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@end

@implementation SMAddSaveMoneyViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self drawShadowWithView:self.view];
    
    
    self.interactiveDismiss = [XWInteractiveTransition interactiveTransitionWithTransitionType:XWInteractiveTransitionTypeDismiss GestureDirection:XWInteractiveTransitionGestureDirectionDown];
    [self.interactiveDismiss addPanGestureForViewController:self];
}

#pragma mark - UITableViewDelegate, UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return SBScaleNumber(50);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        SMAddSaveOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMAddSaveOneTableViewCell" forIndexPath:indexPath];
        
        return cell;
    } else if (indexPath.row == 1) {
        SMAddSaveTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMAddSaveTwoTableViewCell" forIndexPath:indexPath];
        
        return cell;
    } else {
        SMAddSaveTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SMAddSaveTwoTableViewCell" forIndexPath:indexPath];
        
        return cell;
    }
    
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}



- (IBAction)addPhotoAction:(id)sender {
    
}

- (IBAction)overAction:(UIButton *)sender {
    [self dismiss];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


- (instancetype)initWithCoder:(NSCoder *)aDecoder {
    if (self = [super initWithCoder:aDecoder]) {
        self.transitioningDelegate = self;
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.transitioningDelegate = self;
        self.modalPresentationStyle = UIModalPresentationCustom;
    }
    return self;
}

- (void)dismiss{
    if (_delegate && [_delegate respondsToSelector:@selector(presentedOneControllerPressedDissmiss)]) {
        [_delegate presentedOneControllerPressedDissmiss];
    }
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return [XWPresentOneTransition transitionWithTransitionType:XWPresentOneTransitionTypePresent];
}

- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    return [XWPresentOneTransition transitionWithTransitionType:XWPresentOneTransitionTypeDismiss];
}

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator{
    return _interactiveDismiss.interation ? _interactiveDismiss : nil;
}

- (id<UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id<UIViewControllerAnimatedTransitioning>)animator{
    XWInteractiveTransition *interactivePresent = [_delegate interactiveTransitionForPresent];
    return interactivePresent.interation ? interactivePresent : nil;
}

- (void)drawShadowWithView:(UIView *)View {
    
    View.backgroundColor = [UIColor whiteColor];
    //v.layer.masksToBounds=YES;这行去掉
    View.layer.cornerRadius = SBScaleNumber(20);
    View.layer.shadowColor = [UIColor blackColor].CGColor;
    View.layer.shadowOffset = CGSizeMake(2, 5);
    View.layer.shadowOpacity = 1.0;
    View.layer.shadowRadius = 10;
}

@end
